package cn.wolfcode.rbac.web.controller;

import cn.wolfcode.rbac.domain.Department;
import cn.wolfcode.rbac.service.IDepartmentService;
import cn.wolfcode.rbac.util.QueryObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Created by Administrator on 2020/7/12 0012.
 */
@Controller
public class DepartmentController {

    @Autowired
    private IDepartmentService departmentService;

    /**
     * @RequestMapping : 用来接收前台浏览器发送过来的请求
     * 如果匹配上那么会进到这个注解所对应的方法上,
     *
     * @return 在springMVC当中如果返回的是一个字符串, 那么这个字符串是你要返回视图的路径
     */
//    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
//		<property name="prefix" value="/WEB-INF/views/"/>
//		<property name="suffix" value=".jsp"/>
//	</bean>

    @RequestMapping("/department/list")
    public String list(Model model, QueryObject queryObject){
        model.addAttribute("result",departmentService.query(queryObject));
        return "department/list";
    }

    @RequestMapping("/department/delete")
    public String delete(Long id){
        departmentService.delete(id);
        return "redirect:/department/list.do";
    }

    @RequestMapping("/department/input")
    public String input(Model model,Long id){
        //如果id不等null ,那么说明是编辑操作,
        // 编辑操作要求数据回显.
        if(id != null){
            Department department = departmentService.get(id);
            model.addAttribute("entity",department);
        }
        return "department/input";
    }


    @RequestMapping("/department/saveOrUpdate")
    public String saveOrUpdate(Department department){
        departmentService.saveOrUpdate(department);
        return "redirect:/department/list.do";
    }



}
